#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 2e6 + 10;
struct node{
	int cost;
	int eat;
};
node a[N];
LL ans; 
LL t;
int n;

bool cmp(node& a, node& b)
{
	return a.cost * b.eat < a.eat * b.cost;
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i].cost >> a[i].eat;
	}
	
	sort(a + 1, a + n + 1, cmp);
	
	for(int i = 1; i <= n; i++)
	{
		ans += t * a[i].eat;
		t += a[i].cost * 2;
	}
	
	cout << ans << endl;
	
	return 0;
}
